//
//  LIUMainViewController.m
//  EasyNotes
//
//  Created by 劉裕 on 29/5/2016.
//  Copyright © 2016年 劉裕. All rights reserved.
//

#import "LIUMainViewController.h"
#import "LIUNavigationController.h"
#import "LIUListViewController.h"
#import "LIULeftViewController.h"
#import "NSString+Category.h"

@interface LIUMainViewController ()

@end

@implementation LIUMainViewController

#pragma mark - life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupFolder];
    [self setupView];
}

- (void)dealloc {
    [kNotificationCenter removeObserver:self];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)setupFolder {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        NSFileManager *mgr = [NSFileManager defaultManager];
        NSString *createPath = [NSString.document stringByAppendingPathComponent:@"HTML"];
        if (![mgr fileExistsAtPath:createPath]) {
            [mgr createDirectoryAtPath:createPath withIntermediateDirectories:YES attributes:nil error:nil];
        }
    });
}

- (void)setupView {
    
    self.maximumLeftDrawerWidth = 200;
    self.shouldStretchDrawer = NO;
    self.showsShadow = NO;
    
    [kNotificationCenter addObserver:self selector:@selector(openDrawer) name:OpenDrawer object:nil];
    [kNotificationCenter addObserver:self selector:@selector(closeDrawer) name:CloseDrawer object:nil];
    [kNotificationCenter addObserver:self selector:@selector(toggleDrawer) name:ToggleDrawer object:nil];
    LIULeftViewController *leftViewController = [[LIULeftViewController alloc] init];
    leftViewController.mainController = self;
    
    self.centerViewController = leftViewController.navigation;
    self.leftDrawerViewController = leftViewController;
    self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
    self.openDrawerGestureModeMask = MMOpenDrawerGestureModeBezelPanningCenterView;
}

#pragma mark - 抽屉开关

- (void)openDrawer {
    [self openDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}

- (void)closeDrawer {
    [self closeDrawerAnimated:YES completion:nil];
    do {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    } while (0);
}

- (void)toggleDrawer {
    self.openSide == MMDrawerSideNone ? [self openDrawer] : [self closeDrawer];
}

@end
